package com.p7.notepad.activity;

import android.os.Handler;
import android.text.TextUtils;

import com.p7.notepad.R;
import com.p7.notepad.app.BaseActivity;
import com.p7.notepad.app.MyApplication;
import com.p7.notepad.tools.Storage;

public class SplashActivity extends BaseActivity {

    @Override
    public int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    public void initEvents() {
        if (checkPermission()) {
            MyApplication.getInstance().updateNightMode(Storage.getMode());
            Integer time = 2000;
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (!Storage.isLogin()) {
                        startActivity(LoginActivity.class);
                        finish();
                        return;
                    }
                    if (TextUtils.isEmpty(Storage.getName())) {
                        startActivity(LoginActivity.class);
                    } else {
                        startActivity(MainActivity.class);
                    }
                    finish();
                }
            }, time);
        }
    }

    @Override
    protected void onGranted() {
        super.onGranted();
        MyApplication.getInstance().updateNightMode(Storage.getMode());
        Integer time = 2000;
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (!Storage.isLogin()) {
                    startActivity(LoginActivity.class);
                    finish();
                    return;
                }
                if (TextUtils.isEmpty(Storage.getName())) {
                    startActivity(LoginActivity.class);
                } else {
                    startActivity(MainActivity.class);
                }
                finish();
            }
        }, time);
    }
}
